﻿using System;
using System.Web.UI.WebControls;
using FineUI;
using Maticsoft.DBUtility;
using System.Data;
using System.Data.SqlClient;
using System.Net;
using System.Web.UI;

namespace  mydddd.admin
{
    public partial class Login : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

            }
        }

        protected void Button1_OnClick(object sender, EventArgs e)
        {
            try
            {
               
                string dengluSql =
                   @"select u.[ID],u.[LoginName],u.[RealName],
                    u.sysrolepopedom_rname,
                    r.moduleid,
                    r.isdel AS  risdel,u.isdel 
                    from [sysAdmin] u LEFT JOIN  sysRolepopedom  r ON u.sysrolepopedom_rname=r.id 
                    where  u.[LoginName]=@LoginName and u.[Password]=@Password and u.isdel=0 ";
                DataTable dt =
                    DbHelperSQL.Query(dengluSql, new SqlParameter("@LoginName", tb_username.Text.Trim()),
                        new SqlParameter("@Password", tb_pwd.Text)).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    DataRow dr = dt.Rows[0];
                    if (dr["risdel"].ToString() == "1" || dr["isdel"].ToString() == "1")
                    {
                        Alert.Show("此账号已经冻结！");
                        return;
                    }

                    dt.Columns.Remove("risdel");
                    dt.Columns.Remove("isdel");

                    dr = dt.Rows[0];

                    Session["Admin"] = dr;
                    //Response.Write("<script>top.location.href='default.aspx'</script>");

                    //微软ajax控件注册js写法
                    ScriptManager.RegisterStartupScript(this.UpdatePanel2, this.GetType(), "login",
                        "top.location.href='default.aspx'", true);
                }
                else
                {
                    lb1.Text = "账号密码错误,或此账号已冻结！";
                    //JScript.Alert("账号密码错误,或此账号已冻结！", this);//导致样式问题，故换种方式
                    return;
                }


            }
            catch (WebException ex)
            {
                lb1.Text = "系统执行错误，请重试！";
                //JScript.Alert("系统执行错误，请重试！", this);
                return;
            }
        }

    }
}
